package com.donkey.test;

public class ExceptionUtils {

    // 获取最后一次抛出异常的位置信息
    @Deprecated
    public static String getExceptionPosition() {
        StackTraceElement[] stes = Thread.currentThread().getStackTrace();
        StackTraceElement stackTraceElement = null;
        for (int i = 0; i < stes.length; i++) {
            stackTraceElement = stes[i];
            System.out.println(stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName() + " (" + stackTraceElement.getFileName() + ":" + stackTraceElement.getLineNumber() + ")");
            if (stackTraceElement.getFileName().equals("Thread.java") || stackTraceElement.getFileName().equals("ExceptionUtils.java"))
                continue;
            break;
        }
        return stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName() + " (" + stackTraceElement.getFileName() + ":" + stackTraceElement.getLineNumber() + ")";
    }

}
